 var userid=getvl("id");
 $(function(){
 	if(userid!=""){
 		weihuofabu(userid);
 	}else{
 		 $(".p_button").val("确认添加 ");
 	}
 });

function weihuofabu(str){
    	 $.ajax({
      url: urlcore + "/api/expressPrice/selectOne?id="+str,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					var da=data.data;
	               $("#aid").val(da.id);
	               $("#cityResult3").html(da.areaName);
	               $("#lainxiren").val(da.firstMoney);
	               $("#shoujihao").val(da.continuedMoney);
				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}
				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}
			},
			error: function() {
				alert("error");
			}
		});	
		
		$(".p_button").val("确认修改 ");
}



function baochun(){
	 var lainxiren=$("#lainxiren").val();
	 var shoujihao=$("#shoujihao").val();
	 var xiangxidizhi=$("#cityResult3").html();
	var aid=$("#aid").val();
           if(aid!="" && aid!=null){
	    $.ajax({  
        url : urlcore + "/api/expressPrice/update",
        type : "post",  
        contentType: "application/json;charset=utf-8",
        data :JSON.stringify({
        	id:aid,
        	firstMoney:lainxiren,
        	continuedMoney:shoujihao,
        	areaName:xiangxidizhi
        }),
        	dataType: "json",
        success: function(data) {//data是返回的hash,key之类的值，key是定义的文件名 
        	//alert("保存成功!");
        	window.location.href = document.referrer
        },
        error:function(){  
            alert("保存失败");  
        }  
    });
      }else{
      	  $.ajax({  
        url : urlcore + "/api/expressPrice/adds",
        type : "post",  
        contentType: "application/json;charset=utf-8",
        data :JSON.stringify({
        	firstMoney:lainxiren,
        	continuedMoney:shoujihao,
        	areaName:xiangxidizhi,
        	type:1
        }),
        	dataType: "json",
        success: function(data) {//data是返回的hash,key之类的值，key是定义的文件名 
        	//alert("保存成功!");
        	window.location.href = document.referrer
        },
        error:function(){  
            alert("保存失败");  
        }  
    });
      }
}
